// pages/chengyu/chengyu/chengyu.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    xx: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
    xxa: 'A',
    value: ''
  },
  cyMore(e) {
    const _ = this;
    let {
      name
    } = e.currentTarget.dataset
    console.log(name)
    _.setData({
      xsT:name,
      listsId1: name.substr(0, 1),
      listsId2: name.substr(1, 1),
      listsId3: name.substr(2, 1),
      listsId4: name.substr(3, 1)
    })
  },
  getInputValue(e) {
    const _ = this;
    let {
      value
    } = e.detail
    _.setData({
      value
    })
  },
  submit() {
    const _ = this;
    let value = _.data.value;
    wx.request({ //发送请求
      url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=48494&callback=?",
      data: {
        cyname: value
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        };
        console.log(theJson.lists)

        let cyname = theJson.lists[0].cyname

        if (theJson.status == 1) {
          _.setData({
            list: theJson.lists[0],
            listId1: cyname.substr(0, 1),
            listId2: cyname.substr(1, 1),
            listId3: cyname.substr(2, 1),
            listId4: cyname.substr(3, 1)
          })
        }
      }
    })
  },
  tapxx(e) {
    const _ = this;
    const phone = wx.getStorageSync('chengyuphone')
    let {
      xx
    } = e.currentTarget.dataset
    console.log(xx)
    _.setData({
      xxa: xx
    })

    wx.request({ //发送请求
      url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=48494&callback=?",
      data: {
        phone: phone,
        limits: 200,
        sy: xx
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        };
        console.log(theJson.lists)
        if (theJson.status == 1) {
          _.setData({
            lists: theJson.lists,
            nolists:!1
          })
        } else {
          _.setData({
            nolists: 1
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let _ = this;
    wx.request({ //发送请求
      url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=48494&callback=?",
      data: {
        limits: 200,
        sstimes: Date.parse(new Date()),
        sy: 'A'
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        };
        console.log(theJson.lists)
        if (theJson.status == 1) {
          _.setData({
            lists: theJson.lists,
            nolists:!1
          })
        }
      }
    })

    wx.loadFontFace({
      family: 'FZTYSJW',
      source: 'url("http://sd.offcn.com/zg/wximg/2022/gsk/chengyu/FZTYSJW.ttf")',
    });

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '公考成语300斩',
      path:"pages/chengyu/index/index",//当前页面 path ，必须是以 / 开头的完整路径
    }
  }
})